/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package model.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import model.ConnectionFactory;
import model.beans.Horario;

/**
 *
 * @author Juliane Chaerki
 */
public class HorarioDAO {
    private Connection con;  
    private PreparedStatement stmtListar;

    public HorarioDAO() throws Exception {
        con = ConnectionFactory.getConnection();   
    }

    public HorarioDAO(Connection con) throws Exception {
        this.con = con;
    }
    
     public List<Horario> listarHorario() throws Exception {
       stmtListar = con.prepareStatement("SELECT * FROM horario");
       ResultSet rs = stmtListar.executeQuery();
       List<Horario> listaHorario = new ArrayList();
       while(rs.next()){
          Horario hr = new Horario(rs.getInt("idHorario"), rs.getTime("hora"));
          listaHorario.add(hr);
       }
       return listaHorario;
    }
}
